<template>
  <el-container class="home-container" >
    <!--头部区域-->
    <el-header>
      <div>
        <span>小微企业跨组织人才管理系统</span>
      </div>
      <div class="info">
        <img src="../assets/img/logo.png" alt="" srcset="" />
        <!-- 下拉箭头 -->
        <el-dropdown trigger="click" @command="setDialogInfo">
          <span class="el-dropdown-link">
            <i class="el-icon-caret-bottom el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="info">账号设置</el-dropdown-item>
            <el-dropdown-item command="logout" @click="logout"
              >退出登录</el-dropdown-item
            >
            
            <el-dropdown-item command="editpswd">修改密码</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <!-- <el-button type="info" @click="logout">退出</el-button> -->
    </el-header>
    <!--主体区域-->
    <el-container class="container">
      <!--左侧侧边栏-->
      <el-aside :width="isCollapse ? '64px' : '200px'" >
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <el-menu 
          :default-active="activePath"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          background-color="
                rgba(76, 108, 154, 1)"
      
          text-color="#fff"
          active-text-color="#409EFF"
          hover-background-color="red"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
          
        >
          <!--一级菜单-->
          <el-submenu
            v-for="(item, i) in menuList"
            :key="item.id"
            :index="item.id + ''"
          >
            <template slot="title">
              <i :class="menuIcons[i]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <!--二级菜单-->
            <!---router开启为true后，点击菜单跳转的位置为index中的路由-->
            <el-menu-item
              :index="'/' + subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
              @click="saveNavState('/' + subItem.path)"
            >
              <i class="el-icon-menu"></i>
              <span>{{ subItem.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!--主体区域-->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import menu from "./Home.js";
export default {
  data() {
    return {
      menuList: [], //左侧菜单数据
      menuIcons: [
        "iconfont iconyonghuguanli",
        "iconfont iconquanxian",
        "iconfont iconguanli",
        "iconfont iconguanli1",
        "iconfont iconshujutongji",
        "iconfont iconyonghuguanli",
      ], //一级菜单对应的图标
      isCollapse: false, //菜单是否折叠
      activePath: "", //激活菜单的值
    };
  },
  created() {
    this.getMenuList();
    this.activePath = window.sessionStorage.getItem("activePath");
  },
  methods: {
    /**
     * 监听点击
     */
    setDialogInfo(cmdItem) {
      switch (cmdItem) {
        case "info":
          this.setInfo();
          break;
        case "editpswd":
          this.editpswd();
          break;
        case "logout":
          this.logout();
          break;
      }
    },
    /**
     * 账号设置
     */
    setInfo() {
      // this.$router.replace("/");
      this.$router.push("/accountSetting");
     
    },
    /**
     * 修改密码
     */
    editpswd() {
      this.$router.push("/changePwd");
    },
    /**
     * 菜单折叠的切换
     */
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    /**
     * 获取左侧菜单
     */
    async getMenuList() {
      // const {
      //     data: res
      // } = await this.$http.get('menus')
      // if (res.meta.status !== 200) return this.$message({
      //     message: "获取菜单失败",
      //     type: "error"
      // });
      // this.menuList = res.data;
      //模拟获取数据
      this.menuList = menu.row;
    },
    /**
     * 退出操作
     */
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    /**
     * 保存连接点击状态
     */
    saveNavState(activePath) {
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
    /**
     * 菜单展开
     */
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    /**
     * 菜单收起
     */
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>
<style lang="less" scoped>
/deep/ el-menu:hover
{
    background-color:red;
}
.iconfont {
  margin-right: 10px;
}


.home-container {
  height: 100%;

  .el-header {
    // background-color: #373d41;
    background: linear-gradient(
      to bottom,
      rgb(77, 105, 150),
      rgba(84, 115, 160, 1)
    ); 
    /* 标准的语法 */
    // background:rgb(246,246,246);
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: #fff;
    font-size: 20px;

    div {
      display: flex;
      align-items: center;

      img {
        width: 100px;
        height: 100px;
      }

      span {
        margin-left: 15px;
      }
    }

    .info {
      img {
        width: 50px;
        height: 50px;
      }
    }
  }

  .container {
    .el-aside {
     
    //   background: linear-gradient(
    //     to bottom,
    //     rgba(84, 115, 160,1),
    //     rgba(76, 108, 154, 1)
    //   );
      /* 标准的语法 */
 background:rgba(76, 108, 154, 1);
      .toggle-button {
        // display: inline-block;
        // background-color: #4A5064;
        // background: linear-gradient(
        //   to bottom,
        //   rgba(158, 178, 210),
        //   rgba(76, 108, 154, 1)
        // );
        /* 标准的语法 */

        font-size: 10px;
        line-height: 24px;
        color: #fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
      }

      .el-menu {
        border-right: none;
      }
       
    }

    .el-main {
      background-color: #eaedf1;
      height: 100%;
    }
  }
}
</style>